package at.fhooe.mc.master.clc.client.view;

import at.fhooe.mc.master.clc.client.presenter.SimpleLineGraphPresenter.ISimpleLineGraphView;

import com.google.gwt.visualization.client.DataTable;

import com.google.gwt.user.client.Window;
import com.google.gwt.visualization.client.visualizations.corechart.AxisOptions;
import com.google.gwt.visualization.client.visualizations.corechart.LineChart;
import com.google.gwt.visualization.client.visualizations.corechart.Options;

/**
 * View that displays a simple line graph using the google
 * visualization API.
 * For more complex graphs see {@link GraphView} and {@link GraphWithTimeLineView}.
 * @see GraphView
 * @see GraphWithTimeLineView
 * 
 * @author Daniel Karzel
 *
 */
public class SimpleLineGraphView extends AbstractGraphView implements
	ISimpleLineGraphView
{
	public static native DataTable toDataTable(String json) /*-{
	return new $wnd.google.visualization.DataTable(eval("(" + json + ")"));
	}-*/;
	
	@Override
	public void setGraph(String jsonData, String title, String axisTitle)
	{
		Options o = Options.create();
		AxisOptions ao = AxisOptions.create();
		ao.setTitle(axisTitle);
		
		o.setVAxisOptions(ao);
		o.setInterpolateNulls(true);
		//o.set("selectionMode", "multiple");
		
		o.setWidth(Window.getClientWidth() - 100);
		o.setHeight(300);
		
		o.setTitle(title);
		
		LineChart c = new LineChart(
				toDataTable(jsonData), o);
		
		graphTable.setWidget(0, 0, c);
	}
}
